home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / BCCollec / Tools / Search / BCSearcL.cpp next >
Encoding:
Text File  |  1994-04-21  |  2.6 KB  |  96 lines  |  [TEXT/MPS ]

  1. //  The C++ Booch Components (Version 2.1)
  2. //  (C) Copyright 1990-1993 Grady Booch. All Rights Reserved.
  3. //
  4. //  Restricted Rights Legend
  5. //  Use, duplication, or disclosure is subject to restrictions as set forth 
  6. //  in subdivision (c)(1)(ii) of the Rights in Technical Data and Computer 
  7. //  Software clause at DFARS 252.227-7013. 
  8. //
  9. //  BCSearcL.cpp
  10. //
  11. //  This file contains the definitions for the list searching tools.
  12.  
  13. #include "BCSearcL.h"
  14.  
  15. template<class Item, class List>
  16. BC_TListSearch<Item, List>::BC_TListSearch()
  17.   : fIsEqual(0) {}
  18.   
  19. template<class Item, class List>
  20. BC_TListSearch<Item, List>::
  21.   BC_TListSearch(BC_Boolean (*IsEqual)(const Item& x, const Item& y))
  22.     : fIsEqual(IsEqual) {}
  23.   
  24. template<class Item, class List>
  25. BC_TListSearch<Item, List>::~BC_TListSearch() {}
  26.   
  27. template<class Item, class List>
  28. void BC_TListSearch<Item, List>::
  29.   SetIsEqualFunction(BC_Boolean (*IsEqual)(const Item& x, const Item& y))
  30. {
  31.   fIsEqual = IsEqual;
  32. }
  33.  
  34. template<class Item, class List>
  35. BC_TSequentialListSearch<Item, List>::BC_TSequentialListSearch() {}
  36.  
  37. template<class Item, class List>
  38. BC_TSequentialListSearch<Item, List>::
  39.   BC_TSequentialListSearch(BC_Boolean (*IsEqual)(const Item& x, const Item& y))
  40.     : BC_TListSearch<Item, List>(IsEqual) {}
  41.     
  42. template<class Item, class List>
  43. BC_TSequentialListSearch<Item, List>::~BC_TSequentialListSearch() {}
  44.   
  45. template<class Item, class List>
  46. List BC_TSequentialListSearch<Item, List>::Location(const List& target, const Item& key)
  47. {
  48.   List l(target);
  49.   while (!l.IsNull()) {
  50.     if (fIsEqual(l.Head(), key))
  51.       return l;
  52.     l.Tail();
  53.   }
  54.   l.Clear();
  55.   return l;
  56. }
  57.  
  58. template<class Item, class List>
  59. BC_TOrderedListSearch<Item, List>::BC_TOrderedListSearch()
  60.   : fIsLessThan(0) {}
  61.  
  62. template<class Item, class List>
  63. BC_TOrderedListSearch<Item, List>::BC_TOrderedListSearch
  64.   (BC_Boolean (*IsEqual)(const Item& x, const Item& y),
  65.    BC_Boolean (*IsLessThan)(const Item& x, const Item& y))
  66.     : BC_TListSearch<Item, List>(IsEqual),
  67.       fIsLessThan(IsLessThan) {}
  68.     
  69. template<class Item, class List>
  70. BC_TOrderedListSearch<Item, List>::~BC_TOrderedListSearch() {}
  71.   
  72. template<class Item, class List>
  73. void BC_TOrderedListSearch<Item, List>::
  74.   SetIsLessThanFunction(BC_Boolean (*IsLessThan)(const Item& x, const Item& y))
  75. {
  76.   fIsLessThan = IsLessThan;
  77. }
  78.  
  79. template<class Item, class List>
  80. List BC_TOrderedListSearch<Item, List>::
  81.   Location(const List& target, const Item& key)
  82. {
  83.   List l(target);
  84.   while (!l.IsNull()) {
  85.     if (fIsEqual(l.Head(), key))
  86.       return l;
  87.     if (fIsLessThan(key, l.Head())) {
  88.       l.Clear();
  89.       return l;
  90.     }
  91.     l.Tail();
  92.   }
  93.   l.Clear();
  94.   return l;
  95. }
  96.